package net.test.piggy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@EnableWebMvc
@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket getDocket(){
        //创建Docket对象
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())//指定API接口文件首页信息
                .select()//初始化并返回一个API选择构造器
                .apis(RequestHandlerSelectors.any())//为任何接口生成API文档
                .paths(PathSelectors.any())//可以根据url路径设置哪些请求加入文档，忽略哪些请求
                .build();
    }
    private ApiInfo getApiInfo(){
        //创建作者 对象
        Contact contact = new Contact("PIGGY","","smart_piggy@126.com");
        return new ApiInfoBuilder()
                .title("《TITLE》") //文档标题
                .description("文档的描述信息")//文档描述
                .contact(contact)//文档作者
                .version("V1.0")//文档版本
                .build();
    }
}

